package mymac.com.test_3_1;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.json.JSONObject;

/**
 * Created by mymac on 2017/3/1.
 */
public class AddUserActivity extends Activity {
    EditText et_userName, et_userPsw, et_userDeps;
    Button btn_userData;
    SharedPreferences preferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adduser);
        preferences = getSharedPreferences("token", Activity.MODE_PRIVATE);
        et_userName = (EditText) findViewById(R.id.et_adduserName);
        et_userPsw = (EditText) findViewById(R.id.et_adduserPsw);
        et_userDeps = (EditText) findViewById(R.id.et_adduserDeps);
        btn_userData = (Button) findViewById(R.id.btn_adduserdata);

        btn_userData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String token = preferences.getString("token", "");
                String name = et_userName.getText().toString().trim();
                String psw = et_userPsw.getText().toString().trim();
                String deps = et_userDeps.getText().toString().trim();
                String address = "http://a.xl18z.cn/api/users/insert?token=" + token + "&name=" + name + "&password=" + psw + "&department=" + deps;
                HttpActivity.getInstance().getErrMsg(address, new DataCallBack() {
                    @Override
                    public void onErr(Object object) {
                        String errmsg = (String) object;
                        if ("ok!".equals(errmsg)) {
                            finish();
                        }
                    }
                });
            }
        });


    }
}
